//
//  LeanCloudService.m
//  BasketballClub
//
//  Created by 孙鸿吉 on 16/1/9.
//  Copyright © 2016年 孙鸿吉. All rights reserved.
//

#import "LeanCloudService.h"
#import <UIKit/UIKit.h>
static LeanCloudService *service = nil;
@implementation LeanCloudService
+ (LeanCloudService *)shareService
{
    return [[self alloc]init];
}
+ (instancetype)allocWithZone:(struct _NSZone *)zone
{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        if (service == nil) {
            service = [super allocWithZone:zone];
        }
    });
    return service;
}
//时间转换
- (void)setIsFirstLoginWithNumber:(NSInteger)number andKye:(NSString *)key
{
    [[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithInteger:number] forKey:key];
}
- (NSInteger)isFirstLoginWithKey:(NSString *)key
{
    return [[[NSUserDefaults standardUserDefaults] objectForKey:key]integerValue];
}
- (void)setIsCollectWithBool:(BOOL)isCollect andKey:(NSString *)key
{
    [[NSUserDefaults standardUserDefaults] setBool:isCollect forKey:key];
}
- (BOOL)isCollectForKey:(NSString *)key
{
    return [[NSUserDefaults standardUserDefaults] objectForKey:key];
}

//同步
- (void)synchronize
{
    [[NSUserDefaults standardUserDefaults] synchronize];
}
- (NSString *)transTime:(NSDate *)date
{
    
    NSDate *dateNow = [NSDate date];
    NSInteger duration = (NSInteger)[dateNow timeIntervalSince1970] - [date timeIntervalSince1970];
    NSString *string = [NSString new];
    int second = 1;
    int minute = second * 60;
    int hour = minute * 60;
    int day = hour * 24;
    int week = day * 7;
    int month = day * 31;
    if (duration <= 7 * second) {
        string = @"刚刚发布";
    }else if (duration < minute) {
        int n = (int)duration/second;
        string = [NSString stringWithFormat:@"%d秒钟前",n];
    }else if (duration < hour){
        int n = (int)duration/minute;
        string = [NSString stringWithFormat:@"%d分钟前",n];
    }else if (duration < day){
        int n = (int)duration/hour;
        string = [NSString stringWithFormat:@"%d小时前",n];
    }else if (duration < week){
        int n = (int)duration/day;
        string = [NSString stringWithFormat:@"%d天以前",n];
    }else if (duration < month){
        int n = (int)duration/week;
        string = [NSString stringWithFormat:@"%d周以前",n];
    }else if (duration > month){
        string = @"很久以前";
    }
    return string;
}

@end
